<template>
  <div>
    <a-layout id="components-layout-demo-fixed-sider" style="min-height: 100vh">
      <f-sider></f-sider>
      <a-layout>
        <f-header></f-header>
        <a-row type="flex" style="flex: auto">
          <a-row>
            <f-articlesider></f-articlesider>
          </a-row>
          <a-layout-content
            :style="{ margin: '24px 16px 0', overflow: 'initial' }"
          >
            <div :style="{ padding: '24px', background: '#fff' }">
              <a-row type="flex" justify="space-between">
                <a-col class="disflex">
                  <div class="title mr1r">文章评价列表</div>
                </a-col>
              </a-row>
              <a-table
                :columns="columns"
                :rowKey="(data) => data.comment_id"
                :dataSource="data"
              >
                <template slot="user" slot-scope="data">
                  <div>
                    <div>
                      <img :src="data.avatarUrl" />
                    </div>
                    <div>{{ data.nickName }}</div>
                  </div>
                </template>
                <template slot="examine" slot-scope="data, record, index">
                  <a-switch
                    :checked="data.isshow"
                    @change="onChange(data.comment_id, record, index)"
                  />
                </template>
                <template slot="operation" slot-scope="data">
                  <a class="operation" @click="del(data.comment_id)">删除</a>
                </template>
              </a-table>
            </div>
            <f-footer></f-footer>
          </a-layout-content>
        </a-row>
      </a-layout>
    </a-layout>
  </div>
</template>
<script>
import articlesider from "../../components/layout/ArticleSider.vue";
import sider from "../../components/layout/Sider.vue";
import header from "../../components/layout/Header.vue";
import footer from "../../components/layout/Footer.vue";
const columns = [
  {
    title: "评论ID",
    dataIndex: "comment_id",
  },
  {
    title: "用户",
    scopedSlots: { customRender: "user" },
  },
  {
    title: "评论文章",
    dataIndex: "article_title",
  },
  {
    title: "评论内容",
    dataIndex: "comment_content",
  },
  {
    title: "评论时间",
    dataIndex: "comment_create_time",
  },
  {
    title: "审核",
    scopedSlots: { customRender: "examine" },
  },
  {
    title: "操作",
    scopedSlots: { customRender: "operation" },
  },
];

const data = [];

export default {
  metaInfo: {
    title: "文章评论",
  },
  data() {
    return {
      data,
      columns,
      page: 1,
      pageSize: 10,
    };
  },
  components: {
    "f-header": header,
    "f-sider": sider,
    "f-articlesider": articlesider,
    "f-footer": footer,
  },
  mounted() {
    this.$parent.tokenverify();
    this.getCommentList();
    this.setsiders();
  },
  methods: {
    del(e) {
      var _this = this;
      this.$confirm({
        title: "该操作不可逆，确定删除该记录?",
        okText: "是的",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          const url = "/Admin/ArticleComment/delArticleComment";
          const paramObj = {
            comment_id: e,
            token: localStorage.getItem("token"),
          };
          _this.$server.sl("GET", url, paramObj).then((res) => {
            if (res.code == 1) {
              _this.getCommentList();
              _this.$message.success("删除成功");
            } else if (res.code == 4001) {
              _this.$router.push("/Auth/login");
              _this.$message.warning("凭证失效，请重新登陆");
            } else {
              _this.$message.warning(res.msg);
            }
          });
        },
        onCancel() {},
      });
    },
    //获取文章评论
    getCommentList: function () {
      const url = "/Admin/ArticleComment/getCommentList";
      const paramObj = {
        page: this.page,
        pageSize: this.pageSize,
        token: localStorage.getItem("token"),
      };
      this.$server.sl("GET", url, paramObj).then((res) => {
        if (res.code == 1) {
          this.data = res.data;
          console.log(this.data);
        } else if (res.code == 4001) {
          this.$router.push("/Auth/login");
          this.$message.warning("凭证失效，请重新登陆");
        } else {
          this.$message.warning("获取文章分类失败，请刷新重试");
        }
      });
    },
    //设置评论状态
    onChange: function (comment_id, value, index) {
      const url = "/Admin/ArticleComment/setCommentStatus";
      const paramObj = {
        comment_id: comment_id,
        token: localStorage.getItem("token"),
      };
      this.$server.sl("GET", url, paramObj).then((res) => {
        if (res.code == 1) {
          this.data[index].isshow
            ? (this.data[index].isshow = false)
            : (this.data[index].isshow = true);
        } else if (res.code == 4001) {
          this.$router.push("/Auth/login");
          this.$message.warning("凭证失效，请重新登陆");
        } else {
          this.$message.warning("获取文章分类失败，请刷新重试");
        }
      });
    },
    //翻页
    changePage: function (page, pageSize) {
      this.page = page;
      this.pageSize = pageSize;
      this.getlst();
    },
    //菜单选中设置
    setsiders() {
      this.$store.commit("updateselectedKeys", "5");
      this.$store.commit("updateSubmenu", "5-4");
    },
  },
};
</script>
<style scoped>
#components-layout-demo-fixed-sider .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}
.title {
  margin: 0 0 10px;
  font-size: 20px;
}
.picurl {
  height: 3rem;
}
.operation:first-child {
  margin-right: 1rem;
}
.disflex {
  display: flex;
}
img {
  height: 2rem;
  width: 2rem;
}
.mr1r {
  margin-right: 1rem;
}
.btn {
  margin-top: 10px;
}
</style>